package com.bank.bank.customer.controller;

import com.bank.bank.base.response.JsonResult;
import com.bank.bank.base.response.StatusCode;
import com.bank.bank.customer.mapper.CustomerMapper;
import com.bank.bank.customer.pojo.dto.CustomerAddParam;
import com.bank.bank.customer.pojo.entity.Customer;
import com.bank.bank.customer.pojo.vo.CustomerAddVO;
import com.bank.bank.customer.pojo.vo.CustomerInfoVO;
import com.bank.bank.customer.servcie.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/customer")
public class CustomerController {
    //自动装配Service层
    @Autowired
    private CustomerService customerService;

    /**
     * 1.创建客户功能
     * @param customerAddParam
     * @return
     */
    @PostMapping("/add")
    public JsonResult addCustomer(@RequestBody @Validated CustomerAddParam customerAddParam){
        log.debug("customerAddParam:{}", customerAddParam);
        /*
            1.接收客户端传递的数据[已完成];
            2.校验数据的合法性[后期再做];
            3.确认手机号是否被占用[SELECT接口];
              3.1 被占用: 直接返回;
              3.2 未被占用: 插入数据[INSERT接口],返回{"state":2000,"message":"操作成功","data":{}};
         */
        //调用业务层的方法[Service]
        CustomerAddVO customerAddVO = customerService.addCustomer(customerAddParam);

        return JsonResult.ok(customerAddVO);
    }

    /**
     * 2.获取客户列表
     */
    @GetMapping("/list")
    public JsonResult listCustomer(){
        //调用业务层方法
        List<Customer> customerList = customerService.listCustomer();
        return JsonResult.ok(customerList);
    }

    /**
     * 3.获取指定客户信息[包含账户信息]
     */
    @GetMapping("/{customerId}")
    public JsonResult getCustomerById(@PathVariable("customerId") Integer customerId){
        log.debug("customerId:{}", customerId);
        CustomerInfoVO customerInfoVO = customerService.getCustomerById(customerId);

        return JsonResult.ok(customerInfoVO);
    }
}









